package com.personal.website.lottery.table

import java.util
import scala.collection.JavaConverters._

/**
 * Created by Gavin on 2015/12/13.
 */
class EndTable(issue: Int,redBalls: Seq[Int], blueBall: Int) extends Table(issue,redBalls,blueBall){
  override def createRecord() = EndTable.ALL_EXISTS_BALLS.map(x => if(redBalls.contains(x)) x else DEFAULT_NON_EXISTS_VALUE)
  override def toString() = Seq(Seq(issue),Seq(createSum()),createRecord()).flatten.mkString(";")
}

object EndTable{
  def apply(issue: Int,redBalls: Seq[Int], blueBall: Int) = new EndTable(issue,redBalls,blueBall)
  def apply(issue: Int,allBalls: Seq[Int]) = new EndTable(issue,allBalls.init,allBalls.last)
  def newInstance(issue: Integer,redBalls: util.List[Integer],blueBall: Integer) = new EndTable(issue.toInt, redBalls.asScala.map(_.toInt),blueBall.toInt)

  val ALL_EXISTS_BALLS = (1 to 10).flatMap(genSameEndSeq(_))

  def genSameEndSeq(end: Int): Seq[Int] = {
    val list = scala.collection.mutable.ListBuffer[Int]()
    var newEnd = end
    while(newEnd <= 33) {
      list += newEnd
      newEnd += 10
    }
    list
  }

  val headString = Seq("issue","sum",ALL_EXISTS_BALLS).mkString("|")
}
